//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using OpenLS.Drawing;
using OpenLS.Drawing.UI;
using OpenLS.Drawing.UI.Internals;

namespace OpenLS.Chart.UI
{
    sealed class PatternConverter: IMultiValueConverter
    {

        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var style = StrictConverter.Convert<ChartStyle>(values[0]);
            int index = StrictConverter.Convert(values[1], 0);
            var colorScheme = StrictConverter.Convert<ColorScheme>(values[2]);
            return GetBrush(style, index, colorScheme);
        }

        internal static Brush GetBrush(ChartStyle style, int index, ColorScheme colorScheme)
        {
            return ColorBaseToBrushConverter.ColorBaseToBrush(getFillPattern(style).GetColor(index),colorScheme);
        }

        private static FillPattern getFillPattern(ChartStyle style)
        {
            if (style.Index == 41)
                return new FillPattern4();
            switch (style.Index % 8 )
            {
                case 0: return new FadePattern(SchemeColorValue.Accent6);
                case 1: return new FillPattern1();
                case 2: return new AccentFillPattern();
                case 3: return new FadePattern(SchemeColorValue.Accent1);
                case 4: return new FadePattern(SchemeColorValue.Accent2);
                case 5: return new FadePattern(SchemeColorValue.Accent3);
                case 6: return new FadePattern(SchemeColorValue.Accent4);
                case 7: return new FadePattern(SchemeColorValue.Accent5);
                case 8: return new FadePattern(SchemeColorValue.Accent6);
                default: throw new NotSupportedException();
            }

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
